CREATE OR REPLACE FUNCTION delete_all_annotations() RETURNS VOID AS '
BEGIN
	DELETE FROM t_as_annotation;
	DELETE FROM t_annotation;
	DELETE FROM t_annot_set;
	INSERT INTO t_annot_set(as_id, as_name, as_doc_id)
		SELECT nextval(''seq_annot_set''), null, doc_id FROM t_document;
END;
' LANGUAGE 'plpgsql';

-- SELECT delete_all_annotations();